package com.icss.train_sys_back.service.train_manage.impl;

import com.icss.train_sys_back.entity.train_manage.TrainEntity;
import com.icss.train_sys_back.entity.train_manage.TrainNumberEntity;
import com.icss.train_sys_back.mapper.train_manage.TrainMapper;
import com.icss.train_sys_back.service.train_manage.TrainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author 小泽
 * @createTime 2025/9/25 9:40
 */
@Service
public class TrainServiceImpl implements TrainService {
    @Autowired
    private TrainMapper trainMapper;

    //获取车辆列表
    //分页+条件搜索（如果有）
    @Override
    public List<TrainEntity> findTrainListByConditions(String trainNumber, String trainType, Integer status) {
        return trainMapper.findTrainListByConditions(trainNumber,trainType,status);
    }
    //添加车辆
    @Override
    public boolean insert(TrainEntity train) {
        train.setCreateTime(LocalDateTime.now());
        train.setUpdateTime(LocalDateTime.now());

        return trainMapper.insert(train);
    }

    //根据id删除车辆
    @Override
    public boolean delete(Integer id) {
        return trainMapper.delete(id);
    }
    //更新车辆
    @Override
    public boolean update(TrainEntity train) {
        return trainMapper.update(train);
    }

    //获取所有车辆返回给前端
    @Override
    public List<TrainEntity> findAllTrains() {
        return trainMapper.findAllTrains();
    }

    //获取所有车次列表给前端
    @Override
    public List<TrainNumberEntity> findAllTrainNumbers() {
        return trainMapper.findAllTrainNumbers();
    }
}
